from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
from myadmin.models import Users


@receiver(user_logged_in)
def update_user_stats(sender, user, request, **kwargs):
    if isinstance(user, Users):
        # 重新计算并更新目标达成次数和饮食记录总次数
        user.achieved_goals_count = user.achieved_goals_count
        user.diet_records_count = user.diet_records_count
        user.save()